﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace OIDCHybridFlowServer
{
  public class Startup
  {
    public Startup(IConfiguration configuration)
    {
      Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
      // 授权服务器 加载 1.资源 2.客户端 3.用户
      // 1.配置IdentityServer服务
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
      services.AddIdentityServer()
       .AddDeveloperSigningCredential()
       .AddInMemoryApiResources(IdentityServerConfig.GetApis())
       .AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
       .AddInMemoryClients(IdentityServerConfig.GetClients())
       .AddTestUsers(IdentityServerConfig.GetUsers());
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
      }
      // 使用静态文件
      app.UseStaticFiles();
      // 2.使用IdentityServer 中间件
      app.UseIdentityServer();
      //app.UseMvc();
      app.UseMvcWithDefaultRoute();
    }
  }
}
